<template>
  <div>
    <!--  -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{path:'/disecategory'}">疾病分类表</el-breadcrumb-item>
      <el-breadcrumb-item>疾病表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-row :gutter="15">
      <el-col :model="Disease" :span="10">
        <el-input placeholder="请输入内容查询内容 如：心脏病(XZB)" clearable v-model="Disease.diseasename">
          <!-- 当点击搜索的时候调用方法getUserList查询数据 -->
          <el-button slot="append" icon="el-icon-search" @click="search"></el-button>
        </el-input>
      </el-col>
      <el-col :span="4">
        <el-button type="primary" @click="dialogFormVisible = true">添加</el-button>
        <el-dialog title="添加疾病" :visible.sync="dialogFormVisible">
          <el-form :model="form" ref="add">
            <el-form-item label="疾病助记编码：" :label-width="formLabelWidth">
              <el-input v-model="form.diseasecode" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="疾病名称：" :label-width="formLabelWidth">
              <el-input v-model="form.diseasename" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="国际ICD编码：" :label-width="formLabelWidth">
              <el-input v-model="form.diseaseicd" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="疾病所属分类：" :label-width="formLabelWidth">
              <el-input v-model="form.disecategoryid" autocomplete="off"></el-input>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = flase">取 消</el-button>
            <el-button type="primary" @click="add()">确 定</el-button>
          </div>
        </el-dialog>
      </el-col>
    </el-row>
    <el-table :data="tableArray1" border style="width: 100%">
      <el-table-column prop="date" label="编号" type="index" align="center"></el-table-column>
      <el-table-column prop="diseasecode" label="疾病助记编码" align="center"></el-table-column>
      <el-table-column prop="diseasename" label="疾病名称" align="center"></el-table-column>
      <el-table-column prop="diseaseicd" label="国际ICD编码" align="center"></el-table-column>
      <el-table-column prop="disecategoryid" label="疾病所属分类" align="center"></el-table-column>
      <!-- 以后用v-if判断，如果是1 就显示，是0 就不显示 -->
      <!-- <el-table-column prop="DelMark" label="删除标记" align="center">
      </el-table-column>-->
      -->
      <el-table-column label="操作" width="350" align="center">
        <template slot-scope="scope">
          <el-button
            type="primary"
            icon="el-icon-edit"
            @click="open=true;selectdisease(scope.row.diseasename)"
          >修改</el-button>
          <el-button type="primary" icon="el-icon-delete"  @click="deleteDisease(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="personPageInfo.pageNum"
        :page-sizes="[5, 10, 50, 100]"
        :page-size="personPageInfo.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="personPageInfo.total"
      ></el-pagination>
    </div>
    <el-dialog title="修改疾病" :visible.sync="open">
      <!-- ref 对表单数据进行绑定 -->
      <el-form :model="form" ref="update">
        <el-form-item label="疾病助记编码：" :label-width="formLabelWidth">
          <el-input v-model="form.diseasecode" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="疾病名称：" :label-width="formLabelWidth">
          <el-input v-model="form.diseasename" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="国际ICD编码：" :label-width="formLabelWidth">
          <el-input v-model="form.diseaseicd" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="疾病所属分类：" :label-width="formLabelWidth">
          <el-input v-model="form.disecategoryid" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="open=false;CloseForm()">取 消</el-button>
        <el-button type="primary" @click="update()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
export default {
  data() {
    return {
      Disease: {
        diseasename: "",
        pageNum: 1,
        pageSize: 5,
      },
      disecategoryid: this.$route.query.sequenceno,

      tableArray1: [],
      personPageInfo: {
        total: 0,
        pageNum: 1,
        pageSize: 5,
        disecategoryid: this.$route.query.sequenceno,
      },
      tableData: [
        {
          DiseaseCode: "DCSRZ",
          DiseaseName: "大肠湿热证",
          DiseaseICD: "ZZFM11",
          DiseCategoryID: "472",
        },
      ],
      open: false,
      dialogFormVisible: false,
      formLabelWidth: "130px",
      form: {},
    };
  },
  created() {
    this.getDisease();
  },
  methods: {
    // 重置表单
    CloseForm() {
      this.$refs.update.resetFields();
    },

    /**
     * 删除 逻辑删除
     */
    deleteDisease(id) {
      this.$confirm("此操作将执行删除操作, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          const { data: res } = await this.$http.put(
            "diseaseController/deleteDisease",
            {
              id
            }
          );
          if (res.meta.status !== 200) {
            return this.$message.error("删除用户失败！");
          }
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
      //刷新页面
      this.getDisease();
    },


      // 对疾病信息进行修改
  async update(){
      // 修改的方法
      // 获取表单数据
      this.$refs.update.validate(async (valid) => {
        if (!valid) return;
        console.log("zzzzzzzzzzzzzzzzzzzz");
        console.log(this.form);
        console.log("*************************");
        const {
          data: res,
          // 调用后台修改的方法
        } = await this.$http.post(
          "diseaseController/updateByPrimaryKeySelective",
          this.form,
          console.log("zzzzzzzzzzzzzzzzzzzz"),
          console.log(this.form),
          console.log("*************************")
        );
        if (res.meta.status !== 200) {
          return this.$message.error("修改失败！！！！" + res.meta.msg);
          console.log("zzzzzzzzzzzzzzzzzzzz");
          console.log(res);
          console.log("*************************");
        }
        this.$message.success("修改成功!!!!!!");

        //  添加成功，关闭页面
        this.open = false;
        //重置表单
        this.CloseFor();
        //刷新页面
        this.getDisease();
      });
    },

    // 添加
    add() {
      this.$refs.add.validate(async (valid) => {
        if (!valid) return;
        const { data: res } = await this.$http.post(
          "diseaseController/insertSelective",
          this.form
        );
        if (res.meta.status !== 200) {
          return this.$message.error("添加失败！！！！" + res.meta.msg);
          console.log("zzzzzzzzzzzzzzzzzzzz");
          console.log(res);
          console.log("*************************");
        }
        this.$message.success("添加成功");
        //  添加成功，关闭页面
        this.dialogFormVisible = flase;
        //重置表单
        this.CloseFor();
        //刷新页面
        this.getDisease();
      });
    },

    async getDisease() {
      const { data: res } = await this.$http.post(
        "diseaseController/selectDiseaseList",
        this.personPageInfo
      );

      if (res.meta.status !== 200) return this.$message.error(res.meta.msg);

      this.tableArray1 = res.data;
      this.personPageInfo = res.personPageInfo;

      console.log(res);
    },
    // -----------------------------------------
    handleSizeChange(newSize) {
      console.log(`每页 ${newSize} 条`);
      // this.queryInfo.pagesize = newSize

      if (this.Disease.diseasename == "") {
        this.personPageInfo.pageSize = newSize;
        this.getDisease();
      } else {
        this.DiseCategory.pageSize = newSize;
        this.search();
      }
    },

    // 监听 页码值 改变的事件
    handleCurrentChange(newPage) {
      console.log("++++------+++++");
      console.log(`当前页: ${newPage}`);
      // this.queryInfo.pagenum = newPage
      console.log(this.Disease.diseasename);
      console.log("+++++++++++++++");
      if (this.Disease.diseasename == "") {
        this.personPageInfo.pageNum = newPage;
        this.getDisease();
      } else {
        this.Disease.pagenum = newPage;
        this.search();
      }
    },

    open2() {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    updated() {
      // 修改的方法
    },
    add() {
      // 添加的方法
    },
    // 模糊查询
    async search() {
      const { data: res } = await this.$http.post(
        "diseaseController/selectDiseaseByDisease",
        this.Disease
      );
      console.log(res);
      console.log(res.data);
      if (res.meta.status !== 200) {
        return this.$message.error(res.meta.msg);
        console.log("--------------------------------");
        console.log("res.data");
      }
      console.log("*************************");
      console.log(this.tableArray1);
      console.log("--------------------------------");
      console.log(res);
      this.tableArray1 = res.data;
      this.personPageInfo = res.personPageInfo;
    },

    // 修改之前先查询
    async selectdisease(diseasename) {
      //   const {data:res} = await this.$http.get('hissytemcontroller/selectHis')
      const {
        data: res,
      } = await this.$http.post("diseaseController/selectDisease", {
        diseasename,
      });
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg);
      console.log("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
      this.form = res.data;
      console.log(this.form);
      console.log("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
      console.log(res);
    },
  },

};
</script>
<style scoped>
</style>